//
//  YSFeedbackItemView.m
//  Yueshi
//
//  Created by Northwan on 15/8/7.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSFeedbackItemView.h"

@interface YSFeedbackItemView()
@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UIButton *contentBtn;
@end
@implementation YSFeedbackItemView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UILabel *nameLabel = [UILabel new];
        [self addSubview:nameLabel];
        [nameLabel setFont:SYS_FONT(CONTENT_SIZE)];
        self.nameLabel = nameLabel;
        
        UIButton *contentBtn =  [[UIButton alloc]init];
        contentBtn.titleLabel.font = SYS_FONT(CONTENT_SIZE);
        [contentBtn setTitleColor:CONTENT_COLOR forState:UIControlStateNormal];
        contentBtn.titleLabel.numberOfLines = 0;
        [self addSubview:contentBtn];
        self.contentBtn = contentBtn;
        
    }
    return self;
}

-(void)setItemFrame:(YSFeedbackItemFrame *)itemFrame{
    _itemFrame = itemFrame;
    YSFeedbackItem *msg =  itemFrame.msg;
    
    self.nameLabel.frame = itemFrame.nameFrame;
    if (msg.fromType == FeedbackMsgFromSendType) {
        [self.nameLabel setText:@"我"];
    }else{
        [self.nameLabel setText:@"悦"];
    }
    
    UIImage *newImage = nil;
    if (msg.fromType == FeedbackMsgFromSendType) {
        _contentBtn.contentEdgeInsets = UIEdgeInsetsMake(YSPublicXInset, 0, YSPublicXInset, YSPublicXInset);
 
        newImage = [UIImage resizableImageWithName:@"bg_chat_to" offset:5];
    }else{
        _contentBtn.contentEdgeInsets = UIEdgeInsetsMake(YSPublicXInset, YSPublicXInset, YSPublicXInset, 0);
        newImage = [UIImage resizableImageWithName:@"bg_chat_from" offset:5];
    }
    [_contentBtn setTitle:msg.content forState:UIControlStateNormal];
    [_contentBtn setBackgroundImage:newImage forState:UIControlStateNormal];
    [_contentBtn setBackgroundImage:newImage forState:UIControlStateHighlighted];
     _contentBtn.frame = itemFrame.contentFrame;
    self.frame = itemFrame.frame;
}

@end
